import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/views/layout.vue'
import Home from '@/views/home.vue'
import Find from '@/views/find.vue'
import News from '@/views/news.vue'
import User from '@/views/user.vue'
import MyCity from '@/views/MyCity.vue'
// import { getToken } from '@/utils/storage'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      { path: 'home', component: Home },
      { path: 'find', component: Find },
      { path: 'news', component: News },
      { path: 'user', component: User }
    ]
  },
  { path: '/city', component: MyCity }
]

const router = new VueRouter({
  routes
})

export default router
// const whiteList = ['/login', '/register']
// router.beforeEach((to, from, next) => {
//   const token = getToken()
//   if (whiteList.includes(to.path)) {
//     next()
//   } else if (token) {
//     next()
//   } else {
//     router.push('/login')
//   }
// })
